package com.dycx.user.converter;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.user.entity.VehicleTypeDO;
import com.dycx.user.vo.VehicleTypeVO;
import com.dycx.user.dto.VehicleTypeDTO;

/**
 * 车型(CarType)实体转换类
 *
 * @author wuzongbin
 * @since 2024-12-17 15:45:20
 */


@Data
public class VehicleTypeConverter implements Serializable {
    public static VehicleTypeDO dtoToEntity(VehicleTypeDTO dto) {
        if (dto == null) return null;
        VehicleTypeDO entity = BeanUtil.toBean(dto, VehicleTypeDO.class);
        return entity;
    }

    public static VehicleTypeVO entityToVo(VehicleTypeDO entity) {
        if (entity == null) return null;
        VehicleTypeVO vo = BeanUtil.toBean(entity, VehicleTypeVO.class);

        return vo;
    }

    public static List<VehicleTypeVO> entityToVoList(List<VehicleTypeDO> entityList) {
        List<VehicleTypeVO> voList = new ArrayList<>();
        for (VehicleTypeDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<VehicleTypeVO> entityToVoPage(Page<VehicleTypeDO> page) {

        List<VehicleTypeVO> newRecords = new ArrayList<>();

        List<VehicleTypeDO> records = page.getRecords();
        for (VehicleTypeDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<VehicleTypeVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
